#######
# IAAFT Surrogate Properties
#######

y<-iaaft(civil.as.op$d)
y <- Re(y)
civ.d <- spectrum(civil.as.op$d)
civ.y <- spectrum(y)

mydata <- data.frame("h"=c(civil.as.op$d,y),"names"=c(rep("d",length(civil.as.op$d)),rep("y",length(y))))

C <- ggplot(mydata, aes(h, col=names, linetype=names)) +
  geom_freqpoly(binwidth = 2) +  theme_classic() +
  scale_y_continuous(name="n") +
  scale_x_continuous(name="") + ggtitle("C") +
  scale_linetype_manual(values=c("solid", "longdash"))+
  scale_color_manual(values=c('black','skyblue2'))+
  scale_size_manual(values=c(1, 1.5)) +
  theme(plot.title = element_text(size = 16, family = "LM Roman 10"), 
        axis.text=element_text(size=10, family = "LM Roman 10"),
        axis.title=element_text(size=12, family = "LM Roman 10"),
        legend.position="none")


A <- ggplot(civil.as.op, aes(x=date, y=d)) +
  geom_line() + ggtitle("A") +  theme_classic() + 
  scale_y_continuous(name="Data", limits=c(-150, 100)) + 
  labs(x = " ", y = "Data", color = " ", size=1) +
  theme(plot.title = element_text(size = 16, family = "LM Roman 10"), 
        axis.text=element_text(size=10, family = "LM Roman 10"),
        axis.title=element_text(size=12, family = "LM Roman 10"),
        legend.position="none")

B <- ggplot(data.frame("y"=y,"date"=civil.as.op$date), aes(x=date, y=y)) +
  geom_line(col='skyblue2') + ggtitle("B") +  theme_classic() + 
  scale_y_continuous(name="IAAFT Surrogate", limits=c(-150, 100)) + 
  labs(x = " ", y = "IAAFT Surrogate", color = " ", size=1) + 
  theme(plot.title = element_text(size = 16, family = "LM Roman 10"), 
        axis.text=element_text(size=10, family = "LM Roman 10"),
        axis.title=element_text(size=12, family = "LM Roman 10"),
        legend.position="none")

mydata2 <- data.frame("h"=c(log(civ.d$freq),log(civ.y$freq)),
                      "spec"=c(civ.d$spec,civ.y$spec),
                      "names"=c(rep("d",length(civ.d$spec)),rep("y",length(civ.y$spec)))) 

D <- ggplot(mydata2, aes(x=h,y=spec, col=names, linetype=names)) +
  theme_classic() + geom_line(aes(col=names, linetype=names)) +
  scale_y_continuous(name="Amplitude") + scale_x_continuous(name="Frequency") + 
  scale_linetype_manual(values=c("solid", "longdash"))+
  scale_color_manual(values=c('black','skyblue2'))+
  scale_size_manual(values=c(1, 1.5)) + ggtitle("D")   +
  theme(plot.title = element_text(size = 16, family = "LM Roman 10"), 
        axis.text=element_text(size=10, family = "LM Roman 10"),
        axis.title=element_text(size=12, family = "LM Roman 10"),
        legend.position="none")

E <- grid.arrange(A, C, B, D, ncol=2)

ggsave("Surrogate.pdf", plot = E, 
       device = cairo_pdf, width=9.83, height=5, units = "in")  